package mspbots.data.manage.core.client;

import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.data.domain.Page;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Map;

/**
 * mspbots.data.manage.core.client.BaseWebClient
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/8/26
 */
public interface BaseClient {

    /**
     * http get page object
     *
     * @param path         http get path
     * @param params       get params
     * @param responseType return data get class type
     * @return mono default jsonNode  page data result
     */
    <T> Mono<Page<T>> find(String path, Map<String, Object> params, Class<T> responseType);

    /**
     * http get default page  jsonNode objects
     *
     * @param path   http get path
     * @param params get params
     * @return mono default jsonNode page data result
     */
    default Mono<Page<JsonNode>> find(String path, Map<String, Object> params) {
        return this.find(path, params, JsonNode.class);
    }


    /**
     * http post Page object
     *
     * @param path         http post path
     * @param body         post body  params
     * @param responseType post return class type
     * @return mono  post data result
     */
    <T> Mono<Page<T>> search(String path, Object body, Class<T> responseType);

    /**
     * http post default page  jsonNode objects
     *
     * @param path http post path
     * @param body post body params
     * @return mono default jsonNode post data result
     */
    default Mono<Page<JsonNode>> search(String path, Object body) {
        return this.search(path, body, JsonNode.class);
    }

    /**
     * http post flux object
     *
     * @param path         http post path
     * @param body         post body  params
     * @param responseType post return class type
     * @return flux data result flux
     */
    <T> Flux<T> post(String path, Object body, Class<T> responseType);

    /**
     * http post default page  jsonNode objects
     *
     * @param path http post path
     * @param body post body params
     * @return flux default jsonNode post data result
     */
    default Flux<JsonNode> post(String path, Object body) {
        return this.post(path, body, JsonNode.class);
    }

    /**
     * http get object collections
     *
     * @param path         http get path
     * @param params       get query params
     * @param responseType return data get class collections type
     * @return flux data result
     */
    <T> Flux<T> get(String path, Map<String, Object> params, Class<T> responseType);

    /**
     * http get flux jsonNode objects
     *
     * @param path   http get path
     * @param params get body params
     * @return flux default jsonNode post data result
     */
    default Flux<JsonNode> get(String path, Map<String, Object> params) {
        return this.get(path, params, JsonNode.class);
    }

}
